document.addEventListener("backbutton", onBackKeyDown, false);
var lastTime4PressingBackButton = 0;
function onBackKeyDown() {
  // Handle the back button
  console.log("back pressed");
  if (!window.vm || !window.vm.$f7) {
    console.log("**** window.vm or $f7 is null ****");
    return;
  }
  window.vm.$f7.views.main.router.back();
  let now = new Date().getTime();
  if (now - lastTime4PressingBackButton < 2000) {
    window.vm.$f7.dialog.confirm("退出", ()=>{
      console.log("exit");
      if (navigator.app) {
        navigator.app.exitApp();
      } else if (navigator.device) {
        navigator.device.exitApp();
      } else {
        window.close();
      }
    });
  }
  lastTime4PressingBackButton = now;
}